<template>
	<div>
		<el-form ref="form" :rules="rules" :model="form" label-width="100px">
			<el-form-item label="品牌图片" prop="file">
				<el-upload 
					:file-list="filelist"
					action="http://www.abc.com"
					list-type="picture-card"
					:auto-upload="false"
					:limit="1"
					:on-change="changefile"
					:on-remove="removefile">
					<i class="el-icon-plus"></i>
				</el-upload>
			</el-form-item>
<!-- 			<el-form-item label="商品相册" prop="files">
				<el-upload 
					:file-list="filelists"
					action="http://www.abc.com"
					list-type="picture-card"
					:auto-upload="false"
					:limit="10"
					:on-change="changefiles"
					:on-remove="changefiles">
					<i class="el-icon-plus"></i>
				</el-upload>
			</el-form-item> -->
			<el-form-item label="商品相册" prop="files">
					<uploadmore v-model="form.files"></uploadmore>
			</el-form-item>
			<el-form-item>
				<el-button @click="prev">上一步</el-button>
				<el-button type="primary" size="small" @click="next">下一步</el-button>
			</el-form-item>
		</el-form>
		
	</div>
</template>

<script>
export default {
  name: 'ImgForm',
  props: {
  	id: {
  		type: Number,
  		default: 0
  	},
  },
  created() {
  	  console.log("img")
  	  if(this.id){
  		  this.getone()
  	  }else{
		  
		  this.rules.file.push({ required: true, message: '请上传头像', trigger: 'blur' })
		   this.rules.files.push({ required: true, message: '请上传相册', trigger: 'blur' })
	  }
	  
  	  
  },
  data() {
    return {
			form: {
				file: null,
				files: []
			},
			filelist: [],
			filelists: [],
			rules: {
				file: [],
				files: []
			}
    }
  },
  methods: {
		next() {
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.$emit('setForm',this.form)
					this.$emit('next')
				}
			})
		},
		prev() {
			this.$emit('prev')
		},
		getone(){
			this.get('/pms-product/getone',{id: this.id},response => {
				for(let key in this.form) {
					this.form[key] = response[key]
				}
					this.filelist.push({
						name: response.img,
						url: this.img(response.img)
					})
					
					let pics=response.pics.split(", ")
					console.log(pics.length)
					console.log(66666)
					for(let i=0;i<pics.length;i++){
						this.filelists.push({
							name: response.pics,
							url: this.img(pics[i])
						})
					}
				//console.log(this.form.file)
			})
		},
		
		changefile(file) {
			this.form.file = file.raw
			console.log("change")
		},
		removefile() {
			this.form.file = null;
			console.log("rm")
		},
		changefiles(file,files){
			const array=[]
			//this.from.file=files[0].raw
			for(let i=0;i<files.length-1;i++){
				form.filelists.push(files[i])
			}
			array.push(files[0].raw)
			console.log("changelists")
			// console.log(file)
			// console.log(files)
			console.log(file.raw)
		}
  }
}
</script>
<style scoped lang="less">
</style>